/*
 * DialogInfo.java
 *
 * Created on 28 Mei 2008, 11:43
 */
package minimum.spanning.tree;

import java.awt.Color;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import javax.swing.JTable;
import javax.swing.KeyStroke;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  usu
 */
public class DialogInfo extends javax.swing.JDialog {
    /*
     * Serial version UID
     */

    private static final long serialVersionUID = 1L;

    private DefaultTableModel model;

    /** Creates new form DialogInfo
     * @param parent
     * @param modal 
     */
    public DialogInfo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);

        model = new DefaultTableModel();
        model.addColumn("Warna");
        model.addColumn("Lokasi");

        initComponents();

        table.setModel(model);
        table.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
            /*
             * Serial version UID
             */

            private static final long serialVersionUID = 1L;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Color c = (Color) value;
                Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                comp.setBackground(c);
                return comp;
            }
        });
        table.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
            /*
             * Serial version UID
             */

            private static final long serialVersionUID = 1L;

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Point c = (Point) value;
                value = "X = " + c.x + ", Y = " + c.y;
                Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                return comp;
            }
        });

        getRootPane().getActionMap().put("CLOSE", new AbstractAction() {

            /*
             * Serial version UID
             */
            private static final long serialVersionUID = 1L;

            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });
        getRootPane().getInputMap().put(KeyStroke.getKeyStroke((char) KeyEvent.VK_ESCAPE), "CLOSE");
    }

    public void setTreeSImpul(ArrayList<Point> point, ArrayList<Color> color) {
        while (model.getRowCount() > 0) {
            model.removeRow(0);
        }

        for (int i = 0; i < point.size(); i++) {
            model.addRow(new Object[]{color.get(i), point.get(i)});
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        viewPortGlass1 = new usu.widget.glass.ViewPortGlass();
        table = new javax.swing.JTable();
        panelEfect1 = new minimum.spanning.tree.PanelEfect();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();

        viewPortGlass1.setView(table);

        table.setAutoCreateRowSorter(true);
        table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Data Simpul Pohon");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Data Simpul Pohon");

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
        jPanel1.setOpaque(false);

        jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
        jScrollPane1.setOpaque(false);
        jScrollPane1.setViewport(viewPortGlass1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 594, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout panelEfect1Layout = new javax.swing.GroupLayout(panelEfect1);
        panelEfect1.setLayout(panelEfect1Layout);
        panelEfect1Layout.setHorizontalGroup(
            panelEfect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelEfect1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelEfect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        panelEfect1Layout.setVerticalGroup(
            panelEfect1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelEfect1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        getContentPane().add(panelEfect1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private minimum.spanning.tree.PanelEfect panelEfect1;
    private javax.swing.JTable table;
    private usu.widget.glass.ViewPortGlass viewPortGlass1;
    // End of variables declaration//GEN-END:variables
}
